﻿using Furion.DistributedIDGenerator;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using net8.Models;
using net8.Models.Wangzhan;
using net8.Views;

namespace net8.Controllers.Wangzhan
{
    /// <summary>
    /// 网站文档管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WzWenDangController : ControllerBase
    {
        [HttpPost]
        public void Save([FromBody] WzWenDang model)
        {
            if (model.Id == Guid.Empty)
            {
                model.Id = IDGen.NextID();
            }

            model.AddTime = DateTime.Now;
            model.UpdateTime = DateTime.Now;
            model.IsDel = false;
            DbHelper.Db.Storageable(model).ExecuteCommand();
        }

        [HttpDelete]
        public void Delete(Guid id)
        {
            DbHelper.Db.Deleteable<WzWenDang>(id).ExecuteCommand();
        }

        [HttpGet]
        [AllowAnonymous]
        public List<WzWenDang> GetList(Guid id)
        {
            return DbHelper.Db.Queryable<WzWenDang>()
                .WhereIF(Guid.Empty != id, w => w.TypeId == id).OrderBy(w => w.Order).ToList();
        }
    }
}
